/**
 * Copyright (C) 2010, 2011 Neofonie GmbH
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package eu.dicode.analysis.demonstrator.util;

import java.io.IOException;
import java.util.Collection;

import eu.dicode.analysis.demonstrator.model.HomeCommand;

/**
 * Populate a HomeCommand with available query strings.
 */
public final class CommandPopulator {

  private final Collection<String> histQueries;
  private final Collection<String> collocQueries;

  /**Package private constructor for testing only.*/
  CommandPopulator(final String histBasePath, final String collocBasePath) {
    FileSystemScanner scanner = new FileSystemScanner();
    histQueries = scanner.getQueries(histBasePath);
    collocQueries = scanner.getQueries(collocBasePath);
  }

  public CommandPopulator() throws IOException {
    Configuration config = Configuration.getInstance();
    FileSystemScanner scanner = new FileSystemScanner();

    String histBase = config.getStringValue(
        Configuration.DICODE_HISTOGRAM_LOCATION,
        Configuration.DICODE_DEFAULT_HISTOGRAM_LOCATION);
    histQueries = scanner.getQueries(histBase);

    String collocBase = config.getStringValue(
        Configuration.DICODE_COLLOCATION_LOCATION,
        Configuration.DICODE_DEFAULT_COLLOCATION_LOCATION);
    collocQueries = scanner.getQueries(collocBase);
  }

  public void populate(HomeCommand homeCommand) {
    homeCommand.setAllKnownCollocations(this.collocQueries);
    homeCommand.setAllKnownHistograms(this.histQueries);
  }
}
